package com.java.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.dao.IndexHelpMapper;
import com.java.model.IndexHelp;
import com.java.model.IndexSlide;
import com.java.model.MediaAccount;
import com.java.model.Result;
import com.java.service.IndexHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexHelpServiceImpl implements IndexHelpService {

    @Autowired
    private IndexHelpMapper indexHelpMapper;

    @Override
    public Result save(IndexHelp indexHelp) {
        indexHelpMapper.save(indexHelp);
        return Result.success();
    }

    @Override
    public Result modify(IndexHelp indexHelp) {
        indexHelpMapper.modify(indexHelp);
        return Result.success();
    }

    @Override
    public Result remove(int[] ids) {
        for (int id : ids) {
            indexHelpMapper.remove(id);
        }
        return Result.success();
    }

    @Override
    public Result list(IndexHelp indexHelp) {
        PageHelper.startPage(indexHelp.getPageNum(), indexHelp.getPageSize()); // 提醒page在显示哪一页的数据和要显示多少条数据
        List<IndexHelp> list = indexHelpMapper.list(indexHelp);
        PageInfo<IndexHelp> pageInfo = new PageInfo<>(list);

        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public Result get(int id) {
        IndexHelp indexHelp = indexHelpMapper.get(id);
        return Result.success(indexHelp, null);
    }
}
